import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.UUID;

public class Diary {
    private final String id;
    private String title;
    private String content;
    private String category;          // 新增分类字段
    private final LocalDateTime createTime;
    private LocalDateTime lastModifiedTime;
    private String imagePath;         // 新增图片路径字段

    // 初始化时自动生成ID和时间戳
    public Diary(String title, String content) {
        this.id = UUID.randomUUID().toString();
        this.title = title;
        this.content = content;
        this.category = "未分类";       // 默认分类
        this.createTime = LocalDateTime.now();
        this.lastModifiedTime = this.createTime;
    }

    // 核心方法：更新时间戳
    public void updateModifiedTime() {
        this.lastModifiedTime = LocalDateTime.now();
    }

    //------------------ Getter 方法 ------------------//
    public String getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public String getContent() {
        return content;
    }

    public String getCategory() {      // 新增分类获取
        return category;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public LocalDateTime getLastModifiedTime() {
        return lastModifiedTime;
    }

    public String getImagePath() {     // 新增图片路径获取
        return imagePath;
    }

    //------------------ Setter 方法 ------------------//
    public void setTitle(String title) {
        this.title = title;
        updateModifiedTime();          // 修改时自动更新
    }

    public void setContent(String content) {
        this.content = content;
        updateModifiedTime();          // 修改时自动更新
    }

    public void setCategory(String category) {  // 新增分类设置
        this.category = (category == null || category.isEmpty()) ?
                "未分类" : category;
        updateModifiedTime();
    }

    public void setImagePath(String path) {     // 新增图片路径设置
        this.imagePath = path;
        updateModifiedTime();
    }
    public Date getCreateDate() {
        return Date.from(createTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    public Date getLastModifiedDate() {
        return Date.from(lastModifiedTime.atZone(ZoneId.systemDefault()).toInstant());
    }
}